package bean.control;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailHelper {
	public static void sendMemberConfirmMail(String stuNum, String stuName, long memId) {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		String msgBody = stuName + "同學 感謝您註冊原住民與法律教學網\n" +
						   "點選以下連結即可完成認證:\n" +
						   "http://indigenouspeoplesandlaw.appspot.com/confirmMember?id=" + memId;

		try {
			MimeMessage msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress("a0838809919@gmail.com", "admin"));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(stuNum + "@mail.fju.edu.tw", "user"));
			msg.setSubject(stuName + "同學 感謝您註冊原住民與法律教學網", "utf-8");
			msg.setText(msgBody);
			Transport.send(msg);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
